package com.eventos;

import java.util.List;

import org.json.JSONArray;

import com.eventssmartphone.ImageDownloader;
import com.eventssmartphone.JSONReaderListener;
import com.eventssmartphone.R;

import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

public class ActivityVerMapa extends Activity implements JSONReaderListener{
	
	ProgressDialog myProgressDialog = null;
	ListView lista;
	int idEvento;
	private final ImageDownloader imageDownloader = new ImageDownloader();
	/**
	 * @see android.app.Activity#onCreate(Bundle)
	 */
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		// TODO Put your code here
		setContentView(R.layout.ev_vermapa);
		
		Bundle b = getIntent().getExtras();
		
		idEvento = b.getInt("Evento");
		
		ImageView imagen = (ImageView)findViewById(R.id.imgZonas);
		imageDownloader.download(GestorZonas.getInstance().dameUrlMapa(idEvento), imagen);
		
		lista = (ListView) findViewById(R.id.listaZonas);
		
		try{
			GestorZonas.getInstance().dameZonasEvento(idEvento, this);
		}catch(Exception e1){
			Toast.makeText(this, "Error. Revise su conexión a Internet.", Toast.LENGTH_SHORT).show();
		}
	}
	@Override
	public void onConnected() {
		// TODO Auto-generated method stub
		myProgressDialog = ProgressDialog.show(this, "Cargando...", "Por favor esperar...", true);
	}
	@Override
	public void onSent() {
		// TODO Auto-generated method stub
		myProgressDialog.setMessage("Procesando datos...");
	}
	@Override
	public void onFinished(JSONArray jArray) {
		// TODO Auto-generated method stub
		try{
			List<ZonasBean> listaZonas = GestorZonas.getInstance().procesarDameZonasEvento(jArray, idEvento);
			ZonasAdapter adapter = new ZonasAdapter(listaZonas, this);
			lista.setAdapter(adapter);
			if (listaZonas.size()==0)
				Toast.makeText(this, "No se encontraron zonas para el evento.", Toast.LENGTH_SHORT).show();
		}catch(Exception e){
			Toast.makeText(this, "Error. Revise su conexión a Internet.", Toast.LENGTH_SHORT).show();
		}  
		myProgressDialog.dismiss();
	}
}
